import { createRouter, createWebHistory } from "vue-router";
import VueCookies from "vue-cookies";
import routes from "./routes";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes,
});

router.beforeEach((to, _from, next) => {
  const userInfo = (VueCookies as any).get("userInfo");
  if (to.meta.needLogin != null && to.meta.needLogin && userInfo == null) {
    router.push("/login");
  }
  next();
});

export default router;
